package com.google.googlemarket.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

import com.google.googlemarket.R;

/**
 * Created by Administrator on 2017/9/18.
 */

public class Statelayout extends FrameLayout {

    private FrameLayout mView;
    private View mLoading_view;
    private View mFail_view;
    private View mEmptyView;
    private View mContentView;

    public Statelayout(Context context) {
        super(context);
        mView = (FrameLayout) inflate(context, R.layout.state_layout, null);
        mLoading_view = mView.findViewById(R.id.loading_view);
        mFail_view = mView.findViewById(R.id.fail_view);
        mEmptyView = mView.findViewById(R.id.emptyView);
        showLoadingView();
        this.addView(mView);
    }

    public void showLoadingView() {
        showView(mLoading_view);
    }

    public void showFailView() {
        showView(mFail_view);
    }

    public void showEmptyView() {
        showView(mEmptyView);
    }

    public void showContentView() {
        showView(mContentView);
    }

    public void showView(View view) {
        for (int i=0;i<mView.getChildCount();i++){
            View childAt = mView.getChildAt(i);
            childAt.setVisibility(childAt==view?View.VISIBLE:View.GONE);
        }
    }

    /**
     * 设置正常显示的界面
     */
    public void setContentView(int contentlayoutId) {
        View view = View.inflate(getContext(), contentlayoutId, null);
        setContentView(view);
    }

    /**
     * 设置数据正常显示的界面
     */
    public void setContentView(View view) {
        this.mContentView = view;
        mView.addView(view);
        view.setVisibility(View.GONE);
    }
}
